package org.todo.domain;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import org.hibernate.search.annotations.DateBridge;
import org.hibernate.search.annotations.DocumentId;
import org.hibernate.search.annotations.Field;
import org.hibernate.search.annotations.Indexed;
import org.hibernate.search.annotations.IndexedEmbedded;
import org.hibernate.search.annotations.Resolution;

/**
 * Domain class for a todo item
 * @author Matthias Braunhofer
 */
@Entity
@Table(name="todo_todos")
@Indexed
@SuppressWarnings("serial")
public class Todo implements Serializable {
    private int id;
    private String title;
    private String description;
    private String owner;
    private String ownerScreenName;
    private int priority;
    private boolean done;
    private Date creationDate;
    private Date dueDate;
    private Category category;

    @Id
    @GeneratedValue(strategy=GenerationType.AUTO)
    @DocumentId
    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    @Column(length=50)
    @Field
    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    @Column
    @Field
    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(length=20)
    public String getOwner() {
        return owner;
    }

    public void setOwner(String owner) {
        this.owner = owner;
    }

    @Column
    @Field(name="owner")
    public String getOwnerScreenName() {
        return ownerScreenName;
    }

    public void setOwnerScreenName(String ownerScreenName) {
        this.ownerScreenName = ownerScreenName;
    }

    @Column
    public int getPriority() {
        return priority;
    }

    public void setPriority(int priority) {
        this.priority = priority;
    }

    @Column
    public boolean isDone() {
        return done;
    }

    public void setDone(boolean done) {
        this.done = done;
    }

    @Temporal(TemporalType.DATE)
    @Field
    @DateBridge(resolution=Resolution.DAY)
    public Date getCreationDate() {
        return creationDate;
    }

    public void setCreationDate(Date creationDate) {
        this.creationDate = creationDate;
    }

    @Temporal(TemporalType.DATE)
    @Field
    @DateBridge(resolution=Resolution.DAY)
    public Date getDueDate() {
        return dueDate;
    }

    public void setDueDate(Date dueDate) {
        this.dueDate = dueDate;
    }

    @ManyToOne
    @IndexedEmbedded
    public Category getCategory() {
        return category;
    }

    public void setCategory(Category category) {
        this.category = category;
    }
}
